package cn.fuego.busrental.ui.Frament;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.app.ActionBar.LayoutParams;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import cn.fuego.busrental.R;
import cn.fuego.busrental.ui.Home.AreaAdapter;
import cn.fuego.busrental.ui.StyleTour.ContainBusActivity;
import cn.fuego.busrental.ui.StyleTour.NearByPlayActivity;
import cn.fuego.busrental.ui.TraveOrder.TravelOrdelInfoActivity;
import cn.fuego.misp.ui.list.MispListFragment;
import cn.fuego.misp.ui.pop.MispPopListWindow;
import cn.fuego.misp.ui.pop.MispPopWindowListener;


public class HomeFragment extends MispListFragment {

	private View view,rootView;
	private List<String> areaName;
	private int width,height,layoutwidth,popwit;
	private TextView areaOnlyName;
	private PopupWindow popupWindow;
	private LinearLayout titlel; 
	private List<String> dateList;
	private ImageView neayByPlay;
	private AreaAdapter areaAdapter;
	@Override
	public void initRes() {
	    
		this.fragmentRes.setImage(R.drawable.tab_icon_home);
		this.fragmentRes.setName(R.string.frament_start);
        this.fragmentRes.setFragmentView(R.layout.frament_main);
		this.fragmentRes.getButtonIDList().add(R.id.eare_list_btn);
		this.listViewRes.setListItemView(R.layout.item_route_select);
        this.listViewRes.setListView(R.id.route_select_listview);
      
        this.fragmentRes.getButtonIDList().add(R.id.nearby_tour_img);
        this.fragmentRes.getButtonIDList().add(R.id.contain_bus_img);
        this.fragmentRes.getButtonIDList().add(R.id.help_man_img);
	}
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view=super.onCreateView(inflater, container, savedInstanceState);
		areaName=new ArrayList<String>();
		areaName.add("龙华新区");
		areaName.add("南山区");
		areaName.add("福田新区福田新区福田新区福田新区");
		areaName.add("西乡");
		areaAdapter=new AreaAdapter(getActivity(), areaName);
		areaOnlyName=(TextView)view. findViewById(R.id.eare_list_name);
		titlel=(LinearLayout) view.findViewById(R.id.title_l);
		dateList=new ArrayList<String>();
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
		dateList.add("1");
        this.refreshList(dateList);
	    return view;
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.eare_list_btn:
			String[] menuItems1= {
					"福田区",
					"龙华新区",
					"盐田区"
					};
			List<String> list1 = Arrays.asList(menuItems1);	
			MispPopListWindow popWin1 = new MispPopListWindow(getActivity(),new MispPopWindowListener(){
				@Override
				public void onConfirmClick(String value)
				{
					
					areaOnlyName.setText(value);
				}
			},list1);
			popWin1.setLocation(MispPopListWindow.SHOW_CENTER);
			popWin1.setTitle("选择区域");
			popWin1.setShowTitleFlag(true);
			popWin1.showWindow(v,null);
			break;
         
		case R.id.nearby_tour_img:
			NearByPlayActivity.jump(getActivity());
			break;
		case R.id.contain_bus_img:
			
			ContainBusActivity.jump(getActivity());
			break;
		case R.id.help_man_img:
			break;
		default:
			break;
		}
	}
	
	private void showPopupWindow(View view)
	{

		DisplayMetrics metric = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
		width = metric.widthPixels;
		height = metric.heightPixels;
		int layoutwidth = (int) (width * 0.25);
		popwit=(int) (width/2-layoutwidth/3);
		
		View contentView = LayoutInflater.from(getActivity()).inflate(
				R.layout.activity_home_listview, null);
		ListView listView = (ListView) contentView.findViewById(R.id.area_select_listview);
		popupWindow = new PopupWindow(contentView, (int) layoutwidth,
				LayoutParams.WRAP_CONTENT, true);
		listView.setAdapter(areaAdapter);
		popupWindow.setTouchable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.update();
		popupWindow.showAsDropDown(titlel,2,2);
        
		listView.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3)
			{
				areaOnlyName.setText(areaName.get(arg2));
				popupWindow.dismiss();
			}

		
		});

	}


	@Override
	public View getListItemView(View view, Object item) {
		// TODO Auto-generated method stub
		return view;
	}

	

	@Override
	public void onItemListClick(AdapterView parent, View view, long id,
			Object item) {
		 TravelOrdelInfoActivity.jump(getActivity());
	}


	@Override
	public void loadSendList() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public List loadListRecv(Object obj) {
		// TODO Auto-generated method stub
		return null;
	}
}
